<template>
	<el-dialog :close-on-click-modal="false" :title="parameter.id ? ' 查看明细' : '添加'" :visible.sync="show" v-if="show" width="75%" v-loading="loading">
	<div class="search">
			<el-form ref="form" :inline="true" :model="request" label-width="80px">
				<el-row>
					<el-col :span="4">
						<el-form-item>
							<el-select v-model="request.param.type" clearable @change="search" placeholder="请选择">
								<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row>
					<el-card>
						<el-tag :key="tag" v-for="tag in taocanlist" type="danger" effect="dark" style="margin: 0 5px;">
						{{tag}}
						</el-tag>
					</el-card>
				</el-row>
			</el-form>
		</div>

			<br>
			<div class="dataTable" width="100%">
			<el-table :data="listData" stripe border v-loading="listLoading">
				<el-table-column type="index" label="序号" width="55" fixed="left"></el-table-column>
				<el-table-column prop="rname" label="姓名"></el-table-column>
				<el-table-column prop="mnum" label="工号"></el-table-column>
				<el-table-column prop="phone" label="电话"></el-table-column>
				<el-table-column prop="eaddrs" label="子地址"></el-table-column>
				<el-table-column prop="namels" label="套餐名称"></el-table-column>
				<el-table-column prop="xdtm" label="下单时间"></el-table-column>
				<el-table-column prop="jdtm" label="接单时间"></el-table-column>
				<el-table-column prop="cost" label="定价">
				</el-table-column>
				<el-table-column prop="state" label="状态">

					<template slot-scope="scope" v-if="scope.row.state">
						<div v-if="scope.row.state==1">
							<el-tag type="warning">待接单</el-tag>
						</div>
						<div v-if="scope.row.state==2">
							<el-tag type="success">已接单</el-tag>
						</div>
						<div v-if="scope.row.state==3">
							<el-tag>已完成</el-tag>
						</div>
						<div v-if="scope.row.state==4">
							<el-tag type="danger">已拒单</el-tag>
						</div>
					</template>

				</el-table-column>

				<el-table-column label="操作" fixed="right" width="150px">
					<template slot-scope="scope">
						<div class="dataTable-operator">
							<el-button type="info" @click="toUpdate(scope.$index, scope.row)">查看菜品</el-button>
						</div>
					</template>
				</el-table-column>
			</el-table>

				<div class="pageBar">
				<el-pagination @size-change="sizeChange" @current-change="currentChange" :total="listData.total" :page-size="request.page.size"
				 :current-page="request.page.current" :layout="constant.page.layout" :page-sizes="constant.page.pageSizes"></el-pagination>
			</div>

		</div>


		<div slot="footer" class="dialog-footer">
			<center>
				<el-button @click="show = false">关 闭</el-button>
			</center>
		</div>
		<editDialog :parameter="editParameter" :isDisplay.sync="editDisplay"></editDialog>
	</el-dialog>
</template>

<script>
import utils from 'util/utils.js';
import validate from 'util/validate.js';
import constant from 'util/constant.js';
import api from 'api/order/orders/orders.js';
import editDialog from './caipin.vue';
export default {
	name: 'edit',
	components: {
			editDialog
		},
	data() {
		return {
			loading: false,
			show: this.isDisplay,
			request: utils.newRequest(),
			taocanlist: [],
			constant: constant,
			listData: [],
			editDisplay: false,
			editParameter: {},
			show: this.isDisplay,
			options: [
					{
						value: '',
						label: '午餐+晚餐'
					},
					{
						value: 1,
						label: '午餐'
					},
					{
						value: 2,
						label: '晚餐'
					}
				],
		};
	},
	methods: {
		//改变选择项
			selectionChange(val) {
				//清空
				this.request.param.ids = [];
				for (let item of val) {
					this.request.param.ids.push(item.id);
				}
			},
			//改变每页显示数量
			sizeChange(val) {
				this.request.page.size = val;
				this.list();
			},
			//改变现在的页码
			currentChange(val) {
				this.request.page.current = val;
				this.list();
			},
		//去编辑
			toUpdate(index, row) {
				this.editDisplay = true;
				this.editParameter = {
					eaddrs: row.mnum,
					fnames: row.fnames,
					sendact: row.sendact
				};
			},
			//获取数据
			list() {
				this.listLoading = true;
				
				this.request.param.ename = this.parameter.ename;
				this.request.param.jdtm = this.parameter.jdtm;
					api.historyJdPrint(this.request, response => {
						console.log(this.listData.records)
						this.listData = response.data.records;
						
						this.listLoading = false;
					});
			},
			//搜索
		search() {
			this.list();
		},
			init() {
			this.request = utils.newRequest();
				//编辑
				this.request.param.eid = this.parameter.eid;
				this.request.param.jdtm = this.parameter.jdtm;
				api.countTc(this.request, response => {
					this.request.data = response.data;
					const atrr=[]
				console.log(response.data);
					for (let index = 0; index < response.data.length; index++) {
						if(response.data[index].mdh!=undefined){

							var mdh=response.data[index].title+''+response.data[index].mdh +  '份'
							atrr.push(mdh);
						}
						if(response.data[index].fdh!=undefined){
						var fdh=response.data[index].title+''+response.data[index].fdh +  '份'	
								atrr.push(fdh);
						}
					
					if(response.data[index].mfd!=undefined){
					var mfd=response.data[index].title+''+response.data[index].mfd +  '份'	
						atrr.push(mfd);
						}
					if(response.data[index].otrs!=undefined){
						var otrs=response.data[index].title+''+response.data[index].otrs +  '份'
						atrr.push(otrs);
						}
						if(response.data[index].vgtb!=undefined){
						var vgtb=response.data[index].title+''+response.data[index].vgtb +  '份'
						atrr.push(vgtb);
						}
						
					}

						this.taocanlist = atrr;
				});

				this.list();
		}
	},
	props: {
		isDisplay: {
			type: Boolean,
			default() {
				return false;
			}
		},
		parameter: {
			type: Array | Object,
			default() {
				return {};
			}
		}
	},
	watch: {
		isDisplay(val) {
			this.show = val;
			if (val) {
				this.init();
			}
		},
		show(val) {
			this.$emit('update:isDisplay', val);
		},
		parameter(val) {
			this.parameter = val;
		}
	}
};
</script>

<style lang="scss">
@import '~common/custom/css/common.scss';
</style>
